package com.est.dase.database;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
*
* @author Fernando Geraldes, Jaime Santos, Jorge Silva
*
*/
public class DataBase extends SQLiteOpenHelper{

	private static final String TAG = "DbAdapter";

	private static final int DATABASE_VERSION = 1;

	private static String DB_PATH = "/data/data/com.est.dase/databases/";

	private static String DATABASE_NAME = "WAY";

	private static final String TABLE_BLACK_LIST = "BLACK_LIST";
	private static final String TABLE_WHITE_LIST = "WHITE_LIST";
	private static final String TABLE_OPTIONS = "OPTIONS";
	private static final String TABLE_STATUS = "STATUS";

	public DataBase(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);

	}

	@Override
	public void onCreate(SQLiteDatabase dataBase) {

		dataBase.execSQL("CREATE TABLE IF NOT EXISTS "
				+ TABLE_BLACK_LIST
				+ " (BLACK_LIST_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, "
				+ " NAME VARCHAR(200), "
				+ " NUMBER NUMERIC, "
				+ " STATUS_VALUE VARCHAR(2000)); ");
		
		dataBase.execSQL("CREATE TABLE IF NOT EXISTS "
				+ TABLE_WHITE_LIST
				+ " (WHITE_LIST_ID  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, "
				+ " NAME VARCHAR(200), "
				+ " NUMBER NUMERIC, "
				+ " STATUS_VALUE VARCHAR(2000)); ");
		
		dataBase.execSQL("CREATE TABLE IF NOT EXISTS "
				+ TABLE_OPTIONS
				+ " (OPTIONS_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, "
				+ " NAME VARCHAR(200), "
				+ " TYPE NUMERIC, "
				+ " STATUS_VALUE VARCHAR(2000)); ");
		
		dataBase.execSQL("CREATE TABLE IF NOT EXISTS "
				+ TABLE_STATUS
				+ " (STATUS_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, "
				+ " NAME VARCHAR(200), "
				+ " TYPE NUMERIC); ");

	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG, "Upgrading database from version " + oldVersion
				+ " to " + newVersion + ", which will destroy all olddata");
		
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_BLACK_LIST);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_WHITE_LIST);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_OPTIONS);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_STATUS);
		
		onCreate(db);
	}
	
	@SuppressWarnings("unused")
	public void openDataBase() throws SQLException{

		SQLiteDatabase myDataBase;
		//Open the database
		String myPath = DB_PATH + DATABASE_NAME;
		myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

	}

}
